package com.mangohouse.action.core;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.mangohouse.action.BaseAction;
import com.mangohouse.common.Constants;
import com.mangohouse.model.core.SysUser;
import com.mangohouse.service.core.ISysMenuService;
import com.mangohouse.service.core.ISysUserService;

/**
 * 
 * @TODO 用户处理控制器
 * @author roye
 * @date May 17, 2013 2:48:14 PM
 * @version V1.0
 */
@SuppressWarnings("serial")
@Controller("com.mangohouse.core.userAct")
public class SysUserAction extends BaseAction{
	
	

	@Autowired
	private ISysUserService isysUserService;
	
	@Autowired
	private ISysMenuService isysMenuService;
	
	private String userName;

	private String userPwd;
	
	private SysUser user;

	
	/**
	 * 
	* @todo  登录
	* @author roye
	* @date Apr 17, 2013 4:25:06 PM
	* @param   
	* @return String   
	* @throws
	 */
	public String login(){
		userName = user.getLoginName();
		userPwd = user.getUserPwd();
		SysUser sysUser = this.isysUserService.getSysUser(userName, userPwd);
		if (sysUser==null) {
			this.setRequestAttribute("msg","用户名或密码错误！");
			return SUCCESS;
		}
		this.setSessionAttribute(Constants.LOGIN_PERSON_ID, sysUser.getUserId());
		this.setSessionAttribute(Constants.LOGIN_PERSON_NAME, sysUser.getUserName());
		String rstString = this.isysMenuService.getPrivilegeMenuByUser(sysUser);
		this.setRequestAttribute("menuJson", rstString);
		return SUCCESS;
	}
	


	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPwd() {
		return userPwd;
	}

	public void setUserPwd(String userPwd) {
		this.userPwd = userPwd;
	}

	public SysUser getUser() {
		return user;
	}

	public void setUser(SysUser user) {
		this.user = user;
	}
	
	
}
